package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.DeliveryManagement;
import com.intelligent.service.DeliveryManagementService;
import com.intelligent.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/delivery")
public class DeliveryManagementController {

    @Autowired
    private DeliveryManagementService deliveryManagementService;

    @PostMapping("/page")
    public Result<Page<DeliveryManagement>> page(@RequestParam(required = false) Integer pageNum,
                                                 @RequestParam(required = false) Integer pageSize,
                                                 @RequestParam(required = false) String deliveryOrderNo) {
        Page<DeliveryManagement> page = deliveryManagementService.pageList(pageNum, pageSize, deliveryOrderNo);
        return Result.success(page);
    }

    @PostMapping
    public Result<DeliveryManagement> create(@RequestBody DeliveryManagement delivery) {
        try {
            DeliveryManagement created = deliveryManagementService.create(delivery);
            return Result.success(created);
        } catch (Exception e) {
            return Result.error("创建失败：" + e.getMessage());
        }
    }

    @GetMapping("/{id}")
    public Result<DeliveryManagement> detail(@PathVariable Long id) {
        DeliveryManagement detail = deliveryManagementService.detail(id);
        return detail == null ? Result.error("未找到数据") : Result.success(detail);
    }
}


